package com.springcache.service;

import com.springcache.pojo.Book;
import com.springcache.pojo.User;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

@Service
public class BookService {
//	@Cacheable(value = "cache1")
//	@Cacheable(value = {"cache1","cache2"})
//	@Cacheable(value = "books",key = "#id")
	@Cacheable(value = "books",key = "#p0")
	public Book findBookById(Integer id){
		return null;
	}
	@Cacheable(value = "books",key = "#book.id")
	public Book findBookById(Book book){
		return null;
	}
//	@Cacheable(value = "books",key = "#p0.id")
	@Cacheable(value = {"books","mybooks"},key = "caches[1].name")
	public User find(Book book){
		return null;
	}
	@Cacheable(value = "users",key = "#user.id",condition = "#user.id%2==0")
	public User getUser(User user){
		System.out.println("find user by user"+user);
		return user;
	}
//	@CachePut("users")
	@Caching(cacheable = @Cacheable("users"),evict = {@CacheEvict("cache2"),@CacheEvict(value="cache3",allEntries = true)})
	public User find(Integer id){
		return null;

	}
	@CacheEvict(value = "users",allEntries = true)
	public void delete(Integer id){
		System.out.println("delete user by id" + id);
	}
	@CacheEvict(value = "users",beforeInvocation = true)
	public void deleteById(Integer id){
		System.out.println("delete user b‘’‘y id" + id);
	}
}
